from django.conf import settings
from django.core.mail import send_mail

from celery_tasks.main import app


@app.task(bind=True)
def send_verify_email(self, verify_email_url, email):
    try:
        res = send_mail(subject='验证邮件', message=verify_email_url, from_email=settings.EMAIL_HOST_USER,
                  recipient_list=[email])
    except Exception as e:
        print(e)
        res = -1
    # 使用 @app.task(bind=True)  参数时, 任务第一个参数必须是self,  这个self指的是任务本身

    if res == -1:
        self.retry(countdown=5, max_retries=3, exc=Exception('邮件发送失败!'))
